import { TableColumnDataItem } from '../table.interface';
export  class ElTableFormat {

    static getCSSValue(val: string | number):number{
        if (val === 'auto')
            return 0;
        if (!Number.isNaN(+val))
            return +val;
        if (String(val).endsWith('px')) {
            return +String(val).split('px')[0];
        }
        return 0;
    }

    formatRowData(tableRows:any):any{
        var /** @type {?} */ elTableKeys = ['value', 'width', 'index'];
        var /** @type {?} */ tableRowsMap = tableRows.map(function (row:any, index:any) {
            var /** @type {?} */ currentRow:any = {};
            row.forEach(function (item:any) {
                return Object.keys(item).forEach(function (r) {
                    if (elTableKeys.indexOf(r) < 0) {
                        currentRow[r] = item[r];
                    }
                });
            });
            currentRow['index'] = index;
            return currentRow;
        });
        return tableRowsMap;
    }

    static hasClass(el:any, cls:any) {
        if (!el || !cls) return false;
        if (cls.indexOf(' ') !== -1) throw new Error('className should not contain space.');
        if (el.classList) {
          return el.classList.contains(cls);
        } else {
          return (' ' + el.className + ' ').indexOf(' ' + cls + ' ') > -1;
        }
      }
}